import Vue from 'vue'
import VueRouter from 'vue-router'
//引入首页路由
// eslint-disable-next-line no-unused-vars
import Movie from '../views/home/Movie.vue'
// const originaPlus = Router.prototype.push;
// Router.prototype.push = function push(location,onResolve,onReject){
//   if(onResolve || onReject){
//     return originaPlus.call(this,location,onResolve,onReject)
//   }
//   return originaPlus.call(this.location).catch(err=>err)
// }
Vue.use(VueRouter)

const routes = [
  //重定向
  {
    path: '/',
    redirect: '/movie'
  },
  {
    path: '/movie', //根目录
    name: 'movie', //路径名称
    component: Movie,
    //定义子路由
    children: [{
      path: '/movie',
      redirect: '/movie/hot'
    },
    {
      path: 'hot',
      name: 'hot',
      component: () => import( /* webpackChunkName: "hot" */ '../views/home/components/Hot.vue')
    },
    {
      path: 'wait',
      name: 'wait',
      component: () => import( /* webpackChunkName: "wait" */ '../views/home/components/Wait.vue')
    },
    {
      path: 'classics',
      name: 'classics',
      component: () => import( /* webpackChunkName: "classics" */ '../views/home/components/Classics.vue')
    },
    {
      path: 'cinema',
      name: 'cinema',
      component: () => import( /* webpackChunkName: "cinema" */ '../views/home/components/Cinema.vue')
    },
    ]
  },
  {
    path: '/video',
    name: 'video',
    redirect: '/video/recom',
    component: () => import( /* webpackChunkName: "video" */ '../views/Video.vue'),
    children: [{
      path: '/video/jiedu',
      name: 'jiedu',
      component: () => import( /* webpackChunkName: "jiedu" */ '../views/video/components/Jiedu.vue')
    },
    {
      path: '/video/preshow',
      name: 'preshow',
      component: () => import( /* webpackChunkName: "preshow" */ '../views/video/components/Preshow.vue')
    },
    {
      path: '/video/recom',
      name: 'recom',
      component: () => import( /* webpackChunkName: "recom" */ '../views/video/components/Recom.vue')
    },
    {
      path: '/video/say',
      name: 'say',
      component: () => import( /* webpackChunkName: "say" */ '../views/video/components/Say.vue')
    },
    {
      path: '/video/yule',
      name: 'yule',
      component: () => import( /* webpackChunkName: "yule" */ '../views/video/components/Yule.vue')
    },]
  },
  {
    path: '/shortvideo',
    name: 'shortvideo',
    component: () => import( /* webpackChunkName: "shortvideo" */ '../views/Shortvideo.vue')
  },
  {
    path: '/show',
    name: 'show',
    component: () => import( /* webpackChunkName: "show" */ '../views/Show.vue')
  },
  {
    path: '/me',
    name: 'me',
    meta: {
      require: true,
      flag: ''
    },
    component: () => import( /* webpackChunkName: "me" */ '../views/Me.vue')
  },
  {
    path: '/movieitem/:id',
    name: 'movieitem',
    component: () => import( /* webpackChunkName: "movieitem" */ '../views/home/components/MovieItem.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import( /* webpackChunkName: "login" */ '../views/me/components/Login.vue')
  },
  {
    path: '/videoplay',
    name: 'videoplay',
    component: () => import( /* webpackChunkName: "videoplay" */ '../views/video/components/VideoPlay.vue')
  },
  {
    path: '/citylist',
    name: 'citylist',
    component: () => import(/* webpackChunkName: "citylist" */ '../views/CityList.vue')
  },
  {
    "path": "*",
    name: 'page404',
    component: () => import( /* webpackChunkName: "page404" */ '../views/Page404.vue')
  },

]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if (to.meta.require) {
    console.log("需要守卫")
    console.log(to.params.flag)
    if (to.params.flag || to.meta.flag) {
      to.meta.flag = true
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
})
export default router